import { EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { ExcutePlan, RecmInfo, RoundInfo } from "../ExecutePlan";
import { IMoneyStrategy } from "../IMoneyStrategy";
import { IPlan } from "../IExecutePlan";
import { FixedValueStrategy } from "../recmStrategy/FixedStrategy";
import { LdStepV3MoneyStrategy } from "./LdStepMoneyStrategy";
import { FollowResultStrategy } from "../recmStrategy/FollowStrategy";


export class WisdomMoneyStrategyV99V2 implements IMoneyStrategy {
    subPlan: IPlan[];
    debugCompoenent: string = "WisdomMoneyStrategyV99Debug";
    strategyName: string;
    constructor(name?: string) {
        this.strategyName = name ?? "GroupMoneyStrategy" + (new Date()).getMilliseconds() + parseInt((Math.random() * 1000).toString());
        this.subPlan = [];
        this.resetStrategy();
    }
    showMoney(): [EnumBjlResult, number] {
        let zm = 0;
        let xm = 0;
        let recmV = EnumBjlResult.U;
        let recmMoney = 0;


        this.subPlan.forEach(pl => {
            ;
            let [rv, rm] = pl.showMoney();
            pl.recmInfo.recmV = rv;
            pl.recmInfo.recmMoney = rm;

            if (pl.recmInfo.recmV == EnumBjlResult.Z) {
                zm += (pl.recmInfo.recmMoney * pl.multiple);

            }
            else if (pl.recmInfo.recmV == EnumBjlResult.X) {
                xm += (pl.recmInfo.recmMoney * pl.multiple);
            }
        });
        if (zm > xm) {
            recmV = EnumBjlResult.Z;
            recmMoney = zm - xm;
        }
        else if (xm > zm) {
            recmV = EnumBjlResult.X;
            recmMoney = xm - zm;
        }
        else {
            recmV = EnumBjlResult.U;
        }


        return [recmV, recmMoney];
    }
    resetRecm() {
        this.subPlan.forEach(item => item.resetRecm());
    }
    resetStrategy(): void {
        //A计划
        let planA = new ExcutePlan();
        planA.planName = "A计划";
        planA.recmStrategy = [new FixedValueStrategy({ result: EnumBjlResult.Z, reverse: false })]
        planA.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planA.toResult(new RoundInfo());
        //B计划
        let planB = new ExcutePlan();
        planB.planName = "B计划";
        planB.recmStrategy = [new FixedValueStrategy({ result: EnumBjlResult.Z, reverse: true })]
        planB.moneyStrategy = [new LdStepV3MoneyStrategy("", {           
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planB.toResult(new RoundInfo());

        //C计划
        let planC = new ExcutePlan();
        planC.planName = "C计划";
        planC.recmStrategy = [new FollowResultStrategy({ followCount: 1, reverse: false })]
        planC.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planC.toResult(new RoundInfo());
        //D计划
        let planD = new ExcutePlan();
        planD.planName = "D计划";
        planD.recmStrategy = [new FollowResultStrategy({ followCount: 1, reverse: true })]
        planD.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planD.toResult(new RoundInfo());

        //E计划
        let planE = new ExcutePlan();
        planE.planName = "E计划";
        planE.recmStrategy = [new FollowResultStrategy({ followCount: 2, reverse: false })]
        planE.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planE.toResult(new RoundInfo());
        //F计划
        let planF = new ExcutePlan();
        planF.planName = "F计划";
        planF.recmStrategy = [new FollowResultStrategy({ followCount: 2, reverse: true })]
        planF.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planF.toResult(new RoundInfo());
        //G计划
        let planG = new ExcutePlan();
        planG.planName = "G计划";
        planG.multiple = 1;
        planG.recmStrategy = [new FollowResultStrategy({ followCount: 3, reverse: false })]
        planG.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];
        planG.toResult(new RoundInfo());
        //H计划
        let planH = new ExcutePlan();
        planH.planName = "H计划";
        planH.multiple = 1;
        planH.recmStrategy = [new FollowResultStrategy({ followCount: 3, reverse: true })]
        planH.moneyStrategy = [new LdStepV3MoneyStrategy("", {
            winStepMoney: -10,
            failStepMoney: 20,
            baseMoney: 10,
            reverse: false,
            currentMoney: 300,
            jumpCount: 20,
            winLimit: 3,
            failLimit: 3
        })];

        planH.toResult(new RoundInfo());
        this.subPlan = [
            planA, planB,
            planC, planD,
            planE, planF,
            planG, planH
        ];
    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let zm = 0;
        let xm = 0;
        let recmV = EnumBjlResult.U;
        let recmMoney = 0;
        let sumWin = 0;

        this.subPlan.forEach((pl, index) => {
            pl.setResult(roundInfo, pl.recmInfo, pl.multiple, pl.waterRate, pl.fuliRate);
            let userRecmV = pl.toResult(roundInfo);
            let newRoundInfo: RoundInfo = Object.assign({}, roundInfo, { userRecm: userRecmV });
            pl.userRecmInfo.recmV = userRecmV;

            sumWin += (pl.recmInfo.summaryInfo.winMoney - pl.recmInfo.summaryInfo.failMoney);

            let [rv, rm] = pl.toMoney(newRoundInfo, pl.recmInfo, userRecm, pl.baseMoney);
            pl.recmInfo.preBetCount = pl.recmInfo.betCount;
            pl.recmInfo.recmV = rv;
            pl.recmInfo.recmMoney = rm;
            if (rv != EnumBjlResult.U) {
                //pl.recmInfo.
                pl.recmInfo.betCount++;
            }

            if (pl.recmInfo.recmV == EnumBjlResult.Z) {
                zm += pl.recmInfo.recmMoney * pl.multiple;

            }
            else if (pl.recmInfo.recmV == EnumBjlResult.X) {
                xm += pl.recmInfo.recmMoney * pl.multiple;
            }

        });

        if (zm > xm) {
            recmV = EnumBjlResult.Z;
            recmMoney = zm - xm;
        }
        else if (xm > zm) {
            recmV = EnumBjlResult.X;
            recmMoney = xm - zm;
        }
        else {
            recmV = EnumBjlResult.U;
        }


        return [recmV, recmMoney];
    }

    copyValue(valueObj: any): void {
        var obj = valueObj as WisdomMoneyStrategyV99V2;
        if (obj) {
            this.debugCompoenent = obj.debugCompoenent;
            for (let i = 0; i < this.subPlan.length; i++) {
                this.subPlan[i].copyValue(obj.subPlan[i]);
            }
        }
    }
}